/*
    SEL - Simple DirectMedia Layer Extension Library
    Copyright (C) 2001 Matej Knopp <knopp@users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __sel_keyboard_h__
#define __sel_keyboard_h__

#include "sdl.h"

namespace SEL
{

//! Keyboard event handling class.
class Keyboard
{
public:
	//! Enable or disable UNICODE translation of keyboard input.
	/*!
	  This translation has some overhead, so it's default state is
	  disabled. 
	  - If \a enable is 1, translation is enabled.
	  - If \a enable is 0, translation is disabled.
	  - If \a enable is -1, the translation state is not changed.
	  
	  \return the current translation state
	  \param enable as described above
	 */
	static int enableUNICODE (int enable);
	
	//! Enable or disable keyboard repeat
	/*!
	  Keyboard repeat is disabled by default.
	  \note if \a delay is set to 0, keyboard repeat is disabled.
	  \param delay the initial delay in ms between the time when a
	  key is pressed, and keyboard repeat begins.
	  \param interval the time in ms between keyboard repeat events.
 	 */
	static int enableKeyRepeat (int delay = SDL::DEFAULT_REPEAT_DELAY,
				    int interval = SDL::DEFAULT_REPEAT_INTERVAL);
				    
	static Uint8 *keyState (int &numkeys);				   
	//! Get a snapshot of the current state of the keyboard.
	/*!
	  \return an array of keystates, indexed by SDLK_ *syms.
	  \param numkeys reference to an integer used to store the size
	         of the returned array.
	  \sa keyState ()
	 */

	//! Get a snapshot of the current state of the keyboard.
	/*!
	  \return an array of keystates, indexed by SDLK_ *syms.	
	  \par Example:
	  \code
	  Uint8 *keystate = SEL::Keyboard::keyState ()
	  if (keystate [SDLK_RETURN])
	  	cout << "Return is pressed." << endl;
	  \endcode
	  \sa keyState (int &numkeys)
	 */
	static Uint8 *keyState ();
	
	//! Get the current state of modifier keys.
	/*!
	  \return The return value is OR'd combination of the
	  SDLMod enum or one of the following defines:
	  - KMOD_NONE
	  - KMOD_LSHIFT
	  - KMOD_RSHIFT
	  - KMOD_LCTRL
	  - KMOD_RCTRL
	  - KMOD_LALT
	  - KMOD_RALT
	  - KMOD_LMETA
	  - KMOD_RMETA
	  - KMOD_NUM
	  - KMOD_CAPS
	  - KMOD_MODE
	  - KMOD_CTRL (KMOD_LCTRL | KMOD_RCTRL)
	  - KMOD_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
	  - KMOD_ALT (KMOD_LALT | KMOD_RALT)
	  - KMOD_META (KMOD_LMETA | KMOD_RMETA)
	
	  \sa setModState (SDLMod modstate)
	 */
	static SDLMod modState ();
	
	//! Set the current key modifiers state.
	/*!
	  \note This does not change the keyboard state,
	  only the key modifier flags.
	  \param modstate OR'd combination of the SDLMod enum as
	  mentioned in the Keyboard::modState () function.
	 */
	static void setModState (SDLMod modstate);

	//! Get the name of an SDL virtual key symbol.
	/*!
	  \return the SDL defined name of the \a key.
	  \param key the SDL key symbol
	 */
	static char *keyName (SDLKey key);
};

//////////////////////////////////////////////////////////////////
//////////////////////// INLINE FUNCTIONS ////////////////////////
//////////////////////////////////////////////////////////////////

inline int
Keyboard::enableUNICODE (int enable)
{
	return SDL::EnableUNICODE (enable);
}

inline int 
Keyboard::enableKeyRepeat (int delay, int interval)
{
	return SDL::EnableKeyRepeat (delay, interval);
}

inline Uint8 *
Keyboard::keyState (int &numkeys)
{
	return SDL::GetKeyState (&numkeys);
}

inline Uint8 *
Keyboard::keyState ()
{
	return SDL::GetKeyState (NULL);
}

inline SDLMod
Keyboard::modState ()
{
	return SDL::GetModState ();
}

inline void 
Keyboard::setModState (SDLMod modstate)
{
	return SDL::SetModState (modstate);
}

inline char *
Keyboard::keyName (SDLKey key)
{
	return SDL::GetKeyName (key);
}

} // namespace SEL

#endif // __sel_keyboard_h__
